<?php

class Soul_Util_Random {

    static public function generateMd5($str) {
        return md5($str);
    }

    static public function generateUnid($prefix = 'user_', $method = 'md5'){
        $str = 'user_'.rand(1000, 9999).rand(1000, 9999).rand(1000, 9999).rand(100, 999).rand(100, 999);
        $str .= uniqid(hash("md5", time()), TRUE ) . time() . @$_SERVER['REMOTE_ADDR'];
        if($method == 'sha1'){
            return sha1($str);
        }
        return md5($str);
    }
    
    static public function randomNumeric($min = 0, $max = 99999){
		return rand($min, $max).time();
    }
    
    static public function randomCharacters($size = 6, $characters = '123456789abcdefghijklmnopqrstuvwxyz'){
    	$result = '';
    	$len = strlen($characters) - 1;
    	for($i = 0; $i < $size; $i++){
    		$index = rand(0, $len);
    		$result .= $characters[$index];
    	}
    	return $result;
    }    
    
    static public function randomDigits($size = 6, $characters = '0123456789'){
		return self::randomCharacters($size, '0123456789');
    }    
    
    static public function chooseFrom(array $values, $size = NULL){
    	$result = '';
		$size = is_null($size)? rand(1, 10): $size;
    	$len = count($values) - 1;
    	for($i = 0; $i < $size; $i++){
    		$index = rand(0, $len);
    		$result .= $values[$index];
    	}
    	return $result;
    }
}